package com.fxb.project.exam.one;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Test33 extends WindowAdapter implements ActionListener {

    JFrame f;
    JButton bAdd;
    JLabel firstL,secondL,resultL;
    JTextField firstT,secondT,resultT;
    JPanel pan1,pan2,pan3,pan4;

    public static void main(String[] args) {
        Test33 be = new Test33();
        be.go();
    }

    public void go(){
        f = new JFrame("Test33");
        f.setLayout(new GridLayout(4,1));
        f.setSize(350,250);
        firstL = new JLabel("请输入第一个整数：");
        secondL = new JLabel("请输入第二个整数：");
        resultL = new JLabel("相加结果为：");
        bAdd = new JButton("相加");
        bAdd.addActionListener(this);

        firstT = new JTextField("",15);
        secondT = new JTextField("",15);
        resultT = new JTextField("",15);

        pan1 = new JPanel();
        pan1.add(firstL);
        pan1.add(firstT);

        pan2 = new JPanel();
        pan2.add(secondL);
        pan2.add(secondT);

        pan3 = new JPanel();
        pan3.add(bAdd);

        pan4 = new JPanel();
        pan4.add(resultL);
        pan4.add(resultT);

        f.add(pan1);
        f.add(pan2);
        f.add(pan3);
        f.add(pan4);

        f.addWindowListener(this);
        f.setVisible(true);
    }

    public void windowsClosing(WindowEvent e){
        System.exit(0);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == bAdd){
            resultT.setText(String.valueOf(Integer.valueOf(firstT.getText())+Integer.valueOf(secondT.getText())));
        }
    }
}
